/**
 * @file tdsBsp.h
 * @author  xiaowine (xiaowine@sina.cn)
 * @brief
 * @version 01.00
 * @date    2022-03-11
 *
 * @copyright Copyright (c) {2020}  xiaowine
 *
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version <th>Author  <th>Description
 * <tr><td>2022-03-11 <td>1.0     <td>wangh     <td>内容
 * </table>
 * ******************************************************************
 * *                   .::::
 * *                 .::::::::
 * *                ::::::::::
 * *             ..:::::::::::
 * *          '::::::::::::
 * *            .:::::::::
 * *       '::::::::::::::..        女神助攻,流量冲天
 * *            ..::::::::::::.     永不宕机,代码无bug
 * *          ``:::::::::::::::
 * *           ::::``:::::::::'        .:::
 * *          ::::'   ':::::'       .::::::::
 * *        .::::'      ::::     .:::::::'::::
 * *       .:::'       :::::  .:::::::::' ':::::
 * *      .::'        :::::.:::::::::'      ':::::
 * *     .::'         ::::::::::::::'         ``::::
 * * ...:::           ::::::::::::'              ``::
 * *```` ':.          ':::::::::'                  ::::.
 * *                   '.:::::'                    ':'````.
 * ******************************************************************
 */

#ifndef __TDSBSP_H
#define __TDSBSP_H

/* Private includes ----------------------------------------------------------*/
#include "cmsis_os2.h"

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

#define TDS_SEND_NUM          6
#define PROTOCOL_FRAME_MaxLen 15

/* Private macro -------------------------------------------------------------*/
typedef enum {
    PROTOCOL_STACK_IDLE = 0, /*!< Receiver is in idle state. */
    PROTOCOL_STACK_CK,       /*!< Frame is beeing received. */
    PROTOCOL_STACK_RCV,      /*!< Frame is beeing received. */
    PROTOCOL_STACK_CS,       /*!< Frame is beeing received. */
    PROTOCOL_STACK_END,      /*!< If the frame is invalid. */
} UartRcvState;

typedef enum {
    RECV_Wait,   //接收等待
    RECV_Going,  //接收进行
    RECV_Over,   //接收完成
    SEND_Wait,   //发送等待
    SEND_Going,  //发送进行
    SEND_Over,   //发送完成
    INIT_Apply   //初始化
} PROTOCOL_STATUS;

typedef struct {
    // uint8_t CommID;        // 串口号
    // uint8_t Baudrate;      // 通道通讯的波特率
    uint8_t StatckStatus;  // 指示当前协议栈解析状态(空闲->地址解析->)
    uint8_t StatckType;    // 地址类型(私有地址[bit0],全AA或部分AA为组地址[bit1],全99为广播地址[bit2],[bit3...bit6]未使用,保留为0,帧接收成功[bit7])
    uint8_t DataCount;     // 接收到的数据帧长度()
} ProtocolLayer;

/* Private variables ---------------------------------------------------------*/

extern uint16_t tds0;
extern uint16_t tds1;
/* Private function prototypes -----------------------------------------------*/
void    tdsUsartInit(void);
uint8_t tdsSend(void);
void    tdsComService(void);
uint8_t tdsPortSerialReceiveFSM(void);
/* Private user code ---------------------------------------------------------*/

#endif /* __TDSBSP_H */
